package com.randy.fundation;

import java.text.SimpleDateFormat;
import java.util.Locale;

public class TimeUtility {

    private static final long             MILLIS_PER_SECONDS = 1000;
    private static final long             SECONDS_PER_MINUTE = 60;
    private static final long             SECONDS_PER_HOUR   = SECONDS_PER_MINUTE * SECONDS_PER_MINUTE;
    static final         SimpleDateFormat FULL_DATE_FORMAT   = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.US);


    public static String dateTimeText(long stamp) {
        return FULL_DATE_FORMAT.format(new java.util.Date(stamp));
    }

    public static String playTimeText(long millis) {
        long   value = millis / MILLIS_PER_SECONDS;
        String text;
        if (value < SECONDS_PER_HOUR) {
            text = String.format(Locale.getDefault(), "%02d:%02d", value / 60, value % 60);
        } else {
            long hours        = value / (SECONDS_PER_HOUR);
            long otherSeconds = value - hours * SECONDS_PER_HOUR;
            text = String.format(Locale.getDefault(), "%2d:%02d:%02d", hours, otherSeconds / 60, otherSeconds % 60);
        }
        return text;
    }
}
